package com.avicsafety.ezsystem.pdf;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.avicsafety.ezsystem.R;
import com.avicsafety.ezsystem.utils.SDCardUtils;
import com.venusic.handwrite.view.HandWriteView;

import java.io.IOException;

public class HandWriteActivity extends AppCompatActivity {

    private static final String SIGN_PATH = SDCardUtils.getSDCardPath()+"temp/sign.png";
    private Context mContext;

    private HandWriteView hand_write_view;

    private Button btn_ok;
    private Button btn_clear;
    
    

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hand_write);

        mContext = this;

        hand_write_view = findViewById(R.id.hand_write_view);
        btn_ok = findViewById(R.id.btn_ok);
        btn_clear = findViewById(R.id.btn_clear);

        Signature();

        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //hand_write_view.clear();
                if (hand_write_view.isSign()) {
                    try {
                        hand_write_view.save(SIGN_PATH);
                        Intent intent = new Intent();
                        setResult(RESULT_OK,intent);
                        finish();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        btn_clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                hand_write_view.clear();
            }
        });
    }

    private void Signature() {

//        final SignatureView signView = findViewById(R.id.signatureView);
//        signView.setVisibility(View.VISIBLE);
//        signView.setDrawingCacheEnabled(true);
//
//        findViewById(R.id.btn_clear).setOnClickListener(new View.OnClickListener(){
//            @Override
//            public void onClick(final View view) {
//                signView.clear();
//            }
//        });
//        findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener(){
//            @Override
//            public void onClick(final View view) {
//
//                //Bitmap bm=Bitmap.createBitmap(signView.getCachebBitmap());
//                //Bitmap bitmap = signView.getDrawingCache(true);
//                //image.setImageBitmap(bm);
//                //image.setVisibility(View.VISIBLE);
//                signView.clear();
//
//            }
//        });
    }
}
